<?php
include('../../include/functions.inc.php');
$get = isset($_GET["serie"]);

$series = $db->query_select("cllg_factura_serie", "FK_ENTITY=" . $user->entity);
?>

<table width="100%" cellpadding="0" cellspacing="1" class="table table-striped table-hover">
    <tr>
        <th scope="col">Serie Factura</th>
        <th scope="col">Numero Inicial</th>
        <th scope="col">Numero Final</th>
        <th scope="col">Estado</th>
        <th scope="col">Operaciones</th>
    </tr>
    <?php
    $index = 0;
    foreach ($series as $serie) {
        $index++;
        ?>
        <?php if ($get && $serie["SERIE"] == $_GET["serie"]) { ?>
            <tr class="<?= fmod($index, 2) == 0 ? 'line0' : 'line1' ?>">
                <td><input type="text" readonly="readonly" name="SERIE" id="SERIE" value="<?= $serie["SERIE"] ?>"/></td>
                <td><input type="text" name="INICIO" id="INICIO" value="<?= $serie["INICIO"] ?>"/></td>
                <td><input type="text" name="FIN" id="FIN" value="<?= $serie["FIN"] ?>"/></td>
                <td><select name="STATUS" id="STATUS" disabled="disabled">
                        <option value="0" <?= $serie["STATUS"] == 0 ? 'selected="selected"' : "" ?>>Inactivo</option>
                        <option value="1" <?= $serie["STATUS"] == 1 ? 'selected="selected"' : "" ?>>Activo</option>
                        <option value="2" <?= $serie["STATUS"] == 2 ? 'selected="selected"' : "" ?>>Vencido</option>
                    </select></td>
                <td> <INPUT NAME="operation" ID="operation" VALUE="upd" TYPE="HIDDEN"/>
                    <div class="btn-group">
                    <input name="actualiar" onclick="rsv.validate();" type="button" class="btn btn-info" value="Guardar" />
                    <input name="Cancelar" onclick="loadSeries();" type="button" class="btn btn-info" value="Cancelar" />
                    </div>
                </td>
            </tr>
        <?php } else { ?>
            <tr class="<?= fmod($index, 2) == 0 ? 'line0' : 'line1' ?>">
                <td><?= $serie["SERIE"] ?></td>
                <td><?= $serie["INICIO"] ?></td>
                <td><?= $serie["FIN"] ?></td>
                <td><?= $serie["STATUS"] == 1 ? "Activo" : "Inactivo" ?></td>
                <td>
                    <a href="javascript:;" onclick="get('<?= $serie["SERIE"] ?>');">Modificar</a>
                    | <a href="javascript:;" onclick="del('<?= $serie["SERIE"] ?>');">Eliminar</a>
                    <?php if ($serie["STATUS"] == 0) { ?>
                        | <a href="javascript:;" onclick="activate('<?= $serie["SERIE"] ?>');">Activar</a>
                    <?php } ?>
            </tr>
        <?php } ?>
    <?php } ?>
    <?php if (!$get) { ?>
        <tr class="<?= fmod($index, 2) == 0 ? 'line0' : 'line1' ?>">
            <td><input type="text" name="SERIE" id="SERIE"/></td>
            <td><input type="text" name="INICIO" id="INICIO"/></td>
            <td><input type="text" name="FIN" id="FIN"/></td>
            <td>Inactivo
                <INPUT NAME="operation" ID="operation" VALUE="add" TYPE="HIDDEN"/>
            </td>
            <td>
                <input name="Guardar" onclick="rsv.validate();" type="button" class="btn btn-info" value="Guardar" />
            </td>
        </tr>
    <?php } ?>
</table>
